﻿using System;
using System.IO;
using System.Data;
using System.Data.Common;

using SimpleService.Database;
using SimpleService.Config;


using System.Collections.Generic;



namespace testDatabase
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            ConfigHelper cfg = new ConfigHelper();
            cfg.fileName = "mssql";
            cfg.Creat();
            cfg.Set("ConnectionString", "Data Source=(local);User ID=root; Password=123123123qq; Initial Catalog=ServiceSample;");
            cfg.Set("ConnectionStringFormat", "Data Source={DataSource};User ID={Id}; Password={Password}; Initial Catalog={TableName};");
            cfg.Set("DbType", "SimpleService.Database.MssqlProvider");
            cfg.Set("DataSource", "(local)");
            cfg.Set("Id", "root");
            cfg.Set("Password", "123123123qq");
            cfg.Set("TableName", "ServiceSample");


            cfg.fileName = "sqlite";
            cfg.Creat();
            cfg.Set("ConnectionString", "Data Source=" + System.Web.HttpContext.Current.Server.MapPath(".") + "\\Homework.sqlite;Version=3;UTF8Encoding=True;");
            cfg.Set("ConnectionStringFormat", "Data Source={DataSource};Version=3;UTF8Encoding=True;");
            cfg.Set("DbType", "SimpleService.Database.SqliteProvider");
            cfg.Set("DataSource", System.Web.HttpContext.Current.Server.MapPath(".") + "\\Homework.sqlite" );


            cfg.fileName = "access";
            cfg.Creat();
            cfg.Set("ConnectionString", String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Jet OLEDB:Database Password={1};", System.Web.HttpContext.Current.Server.MapPath(".") + "\\#ServiceSample %20DB.mdb", "123123123qq") );
            cfg.Set("ConnectionStringFormat", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={DataSource};Jet OLEDB:Database Password={Password};");
            cfg.Set("DbType", "SimpleService.Database.AccessProvider");
            cfg.Set("DataSource", System.Web.HttpContext.Current.Server.MapPath(".") + "\\#ServiceSample %20DB.mdb" );
            cfg.Set("Password", "123123123qq");

            cfg.fileName = "mysql";
            cfg.Creat();
            cfg.Set("ConnectionString", String.Format("Data Source={0};User Id={1}; Password={2}; Database={3}; pooling=false", "82.103.129.94", "simpleservicee", "123123123qq", "simpleservicee") );
            cfg.Set("ConnectionStringFormat", "Data Source={0};User Id={1}; Password={2}; Database={3}; pooling=false" );
            cfg.Set("DbType", "SimpleService.Database.MysqlProvider");
            cfg.Set("DataSource", "82.103.129.94");
            cfg.Set("Id", "simpleservicee");
            cfg.Set("Password", "123123123qq");
            cfg.Set("TableName", "simpleservicee");

            cfg.fileName = "postgresql";
            cfg.Creat();            
            cfg.Set("ConnectionString", String.Format("Server={0};User ID={1}; Password={2}; Database={3};Port=5432;Encoding=UNICODE;", "188.40.70.21", "simpleservice", "123123123qq", "simpleservice") );
            cfg.Set("ConnectionStringFormat", "Server={DataSource};User ID={Id}; Password={Password}; Database={TableName};Port=5432;Encoding=UNICODE;");
            cfg.Set("DbType", "SimpleService.Database.PostgresqlProvider");
            cfg.Set("DataSource", "188.40.70.21");
            cfg.Set("Id", "simpleservicee");
            cfg.Set("Password", "123123123qq");
            cfg.Set("TableName", "simpleservicee");

            cfg.fileName = "mssql";
            string strDbCon = cfg.Get("ConnectionString");
            DbOperation dbo = new DbOperation(cfg.Get("DbType"));

            
            DbConnection connection = dbo.GetConnection(strDbCon);
            DbCommand cmd = dbo.GetCommand("SELECT * FROM Users", connection);
            DbDataAdapter adp = dbo.GetDataAdapter(cmd);

            DataSet ds = new DataSet();
            adp.Fill(ds,"tt");


            Response.Write(ds.Tables["tt"].Rows[0]["uid"].ToString());
            Response.Write(ds.Tables["tt"].Rows[0]["password"].ToString());

            Response.Write("<br>");

            Dictionary<string, Type> allDbType = DbLoader.GetDbTypes();

            foreach (KeyValuePair<string, Type> dllPath in allDbType)
            {
         

                Response.Write(dllPath.Key);
                Response.Write("<br>");
            }
            
            

        }



    }
}